package com.software.chemistry.controller;

import com.software.chemistry.entity.Collection;
import com.software.chemistry.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/collection")
public class CollectionController {

    @Autowired
    private CollectionService collectionService;


    @GetMapping("/collectModel")
    public Collection collectModel(@RequestParam(name = "userId") String userId,
                                   @RequestParam(name = "modelId") String modelId){

        Collection collection = new Collection();
        collection.setUserId(userId);
        collection.setModelId(modelId);
        Collection save = collectionService.creatCollection(collection);
        return save;
    }

    @GetMapping("/findCollection")
    public Collection findCollection(@RequestParam(name = "userId") String userId,
                                   @RequestParam(name = "modelId") String modelId){

        Collection find = collectionService.findCollection(userId, modelId);
        return find;
    }

    @GetMapping("/noCollectModel")
    public void noCollectModel(@RequestParam(name = "userId") String userId,
                                   @RequestParam(name = "modelId") String modelId){
        Collection find = findCollection(userId, modelId);
        collectionService.deleteCollection(find);
    }
}
